package com.liang.two;

import com.rabbitmq.client.*;
import utils.RabbitmqUtil;

import javax.xml.transform.Source;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * User: XIAOLIANG
 * Date: 2021/6/17
 * Time: 17:29
 * Description: 这是一个工作线程 相当于之前的消费者
 */
public class Work01 {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitmqUtil.getChannel();

        DeliverCallback deliverCallback = new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery message) throws IOException {
                System.out.println("接受到的消息:"+new String(message.getBody()));
            }
        };

        CancelCallback cancelCallback = new CancelCallback() {
            @Override
            public void handle(String consumerTag) throws IOException {
                System.out.println(consumerTag+"消息被消费者取消消费 接口回调逻辑");
            }
        };

        // 消息的接受

        /**
         * 1 消费哪个队列
         * 2 消费成功后是否要自动应答
         * 3 消费者未成功消费 的回调
         * 4 消费者 取消消费的回调
         */
        System.out.println("c2等待接受消息......");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);


    }

}